package org.example.chapter3;

import java.util.Scanner;

public class HexDigit2Dec {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter a hex digit: ");
        String hex = in.nextLine();

        if (hex.length() != 1) {
            System.out.println("Invalid hex digit");
            System.exit(1);
        }

        char ch=Character.toUpperCase(hex.charAt(0));
        if('A'<=ch && ch<='F'){
            int value=ch-'A'+10;
            System.out.println("The hex digit "+ch+" is "+value);
        }else if(Character.isDigit(ch)){
            System.out.println("The hex digit "+ch+" is "+ch);
        }else{
            System.out.println("Invalid hex digit");
        }
    }
}
